<?php


namespace App\Admin\Controllers;


use Dcat\Admin\Controllers\AdminController;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Models\Repositories\Administrator;

class AdminMobileController extends AdminController
{
    protected $title = "管理员电话";

    protected function grid()
    {
        return Grid::make(new Administrator(), function (Grid $grid) {
            $grid->id('ID')->sortable();
            $grid->username;
            $grid->mobile;

            $grid->showQuickEditButton();
            $grid->disableFilterButton();
            $grid->disableDeleteButton();
            $grid->disableCreateButton();
            $grid->disableViewButton();
        });
    }

    public function form()
    {
        return Form::make(new Administrator(), function (Form $form) {
            $userTable = config('admin.database.users_table');

            $connection = config('admin.database.connection');

            $id = $form->getKey();

            $form->display('id', 'ID');

            $form->text('username', trans('admin.username'))
                ->required()
                ->creationRules(['required', "unique:{$connection}.{$userTable}"])
                ->updateRules(['required', "unique:{$connection}.{$userTable},username,$id"]);

            $form->mobile('mobile');

        })->saving(function (Form $form) {

        });
    }
}